package com.example.kafka.controller;

import com.example.kafka.domain.*;
import com.example.kafka.mapper.*;
import com.example.kafka.vo.Result;
import org.apache.kafka.common.protocol.types.Field;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class MachineController {

    @Autowired
    private CabinetDoorMapper cabinetDoorMapper;

    @Autowired
    private ConveyerBeltMapper conveyerBeltMapper;

    @Autowired
    private MoneyBeltMapper moneyBeltMapper;

    @Autowired
    private PrinteMachineMapper printeMachineMapper;

    @Autowired
    private ScreenMapper screenMapper;




    @GetMapping("/current-machine-data")
    public Object queryCurrentMachineData(Integer machineId){
        // 柜门
        CabinetDoor cabinetDoor = cabinetDoorMapper.queryLatestData(machineId);
        // 传送带
        ConveyerBelt conveyerBelt = conveyerBeltMapper.queryLatestData(machineId);
        // 钞带
        MoneyBelt moneyBelt = moneyBeltMapper.queryLatestData(machineId);
        // 打印机
        PrinteMachine printeMachine = printeMachineMapper.queryLatestData(machineId);
        // 显示屏
        Screen screen = screenMapper.queryLatestData(machineId);



        Map<String,Object> resultMap = new LinkedHashMap<>();
        resultMap.put("CHECKTIME",cabinetDoor.checkTime);
        resultMap.put("柜门",cabinetDoor);
        resultMap.put("传送带",conveyerBelt);
        resultMap.put("钞带",moneyBelt);
        resultMap.put("打印机",printeMachine);
        resultMap.put("显示屏",screen);

        return Result.success(resultMap, resultMap.size());

    }

}
